import {setAddress} from '../../utils/settings'
Page({

    data: {
        //用户基本信息，初始数据
        userInfo:{},

        //可选择的基本信息
        allDisabilityType: ["儿麻后遗症", "骨关节疾患", "畸形", "脊柱脊髓伤病", "截/缺肢", "截瘫",
            "精神", "脑瘫", "偏瘫", "视力", "听力", "言语", "肢体", "智力", "周围神经损伤"
        ],
        allDisabilityCause: ["产伤", "创伤或意外伤害", "发育畸形", "感染", "骨关节病", "疾病", "脊髓灰质炎",
            "脊髓损伤", "交通事故", "脑性瘫痪", "脑血管疾病", "其他外伤", "先天性损伤或发育障碍", "原因不明",
            "早产", "窒息", "中毒"],
        allDisabilityLevel: ["未定级", "一级", "二级", "三级", "四级"],
        allBehaviorPhase: ["未评估", "初次", "中期", "末期"],
    },

    addscore: function () {
        wx.navigateTo({
            url: '/pages/index/index',
        })
    },
    bindNameChange(e) {
        this.data.userInfo.name = e.detail.value
    },
    bindGenderChange(e) {
        this.data.userInfo.record.gender = e.detail.value
    },
    bindAgeChange(e) {
        this.data.userInfo.record.age = e.detail.value
    },
    bindDisabilityTypeChange(e) {
        this.setData({
            'userInfo.record.disabilityType': this.data.allDisabilityType[e.detail.value]
        })

    },
    bindDisabilityCauseChange(e) {
        this.setData({
            'userInfo.record.disabilityCause': this.data.allDisabilityCause[e.detail.value]
        })
    },
    bindDisabilityLevelChange(e) {
        this.setData({
            'userInfo.record.disabilityLevel': this.data.allDisabilityLevel[e.detail.value]
        })
    },
    bindBehaviorPhaseChange(e) {
        this.setData({
            'userInfo.record.behaviorPhase': this.data.allBehaviorPhase[e.detail.value]
        })
    },
    saveInfo: function () {
        wx.request({
            url: setAddress,
            data: this.data.userInfo,
            method: "POST",
            success:(res)=>{
              wx.setStorageSync("userInfo", this.data.userInfo)
              wx.setStorageSync('changed', 1)
              console.log(wx.getStorageSync("userInfo"))
              wx.navigateBack()   
            },
            fail:(err)=>{
              wx.showToast({
                title: '保存失败',
                icon: 'error'
              })
            }
          })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onShow: function (options) {
        this.setData({
            userInfo: wx.getStorageSync("userInfo")
        })
        console.log(wx.getStorageSync("userInfo"))
    },


})